package com.zz.framework.core.view

import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView

import com.zz.framework.core.ext.dp2px
import com.zz.framework.core.view.BaseUIFactory
import com.zz.framework.R


/**
 * Copyright © 2019 zanezhao All rights reserved.
 * @author: zanezhao
 * @email: 1820022519@qq.com
 * @version: V1.0
 */
class SimpleBaseUIFactory(context: Context) : BaseUIFactory(context) {
    override val titleBackButtonLeftMargin: Int
        get() = 2.dp2px()

    override val titleBackButtonTopMargin: Int
        get() = 0.dp2px()

    override val titleBackButtonBottomMargin: Int
        get() = 0.dp2px()

    override val titleRightImageButtonRightMargin: Int
        get() = 2.dp2px()

    override val titleRightImageButtonTopMargin: Int
        get() = 0.dp2px()

    override val titleRightTextButtonRightMargin: Int
        get() = 2.dp2px()

    override val titleRightTextButtonTopMargin: Int
        get() = 2.dp2px()

    override val titleBackagegroundDrawbleRes: Int
        get() = 0

    override val titleBackagegroundColorRes: Int
        get() = 0

    override val progressDialogSize: Int
        get() = 70.dp2px()

    override fun createTitleBackButton(): View {
        val iv = ImageView(mContext)
        iv.setPadding(10.dp2px(), 0, 10.dp2px(), 0)
        iv.setImageResource(R.drawable.ic_arrow_back_white_24dp)
        return iv
    }

    override fun createTitleRightImageButton(resId: Int): View {
        val iv = ImageView(mContext)
        iv.setImageResource(resId)
        return iv
    }

    override fun createTitleRightTextButton(text: String): View {
        val v = LayoutInflater.from(mContext).inflate(R.layout.textview_titleright, null) as TextView
        v.text = text
        return v
    }

    override fun createTitleRightTextButton(textId: Int): View {
        val v = LayoutInflater.from(mContext).inflate(R.layout.textview_titleright, null) as TextView
        v.setText(textId)
        return v
    }

    override fun createProgressDialog(): View {
        val context = mContext
        val layout = FrameLayout(context)
        layout.setBackgroundResource(R.drawable.loading_bg)
        val pb = ProgressBar(context)
        pb.isIndeterminate = true
        val pbSize = FrameLayout.LayoutParams.WRAP_CONTENT
        val lpPb = FrameLayout.LayoutParams(pbSize, pbSize)
        lpPb.gravity = Gravity.CENTER
        layout.addView(pb, lpPb)
        return layout
    }

    override fun createYesNoDialog(
        context: Context,
        yesText: String,
        noText: String,
        message: String,
        titleIcon: Int,
        title: String,
        listener: DialogInterface.OnClickListener
    ): Dialog {
        val b = AlertDialog.Builder(context)
        b.setMessage(message).setPositiveButton(yesText, listener)
        if (noText != null) {
            b.setNegativeButton(noText, listener)
        }
        if (titleIcon != 0) {
            b.setIcon(titleIcon)
        }
        if (title != null) {
            b.setTitle(title)
        }
        return b.create()
    }

}
